package com.xd.center.http.authentication;

import com.xd.center.http.builder.MethodMetadata;
import com.xd.center.http.proxy.HttpProxy;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

@Slf4j
public class ApiAuth implements HttpAuth {

  @SneakyThrows
  @Override
  public void auth(MethodMetadata methodMetadata, HttpProxy httpProxy, Map<String, String> headers, boolean resetAuth) {
    String url = methodMetadata.getDefaultUrl();
    if (url.indexOf("?") == -1) {
      url += "?";
    } else {
      url += "&";
    }
    url += "key=" + methodMetadata.getServerMap().get(AUTH_KEY);
    methodMetadata.setUrl(url);
  }
}